package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 
 * 工本费收取 2016-12-05
 * @author ZhaoYuJing 
 * 
 * NieCR 评审 2016-12-05
 *
 */

@Entity
@Indexed
@Table(name = "travel_costprice")
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "operateDate") })
public class CostPrice extends BaseModel {

	private static final long serialVersionUID = -5700140722001007213L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	@In
	private Long pkCostPrice;
	
	/** 合同签约 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkTravelContract")
	@IndexedEmbedded(depth = 1)
	private TravelContract travelContract;
	
	/** 办理日期*/
	@Field
	@Column
	@Between
	private Date operateDate;
	
	/** 工本费*/
	@Field
	@Column
	private Double flatCost;
	
	/** 备注*/
	@Field
	@Column
	private String cause;
	
	/** 收费状态*/
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private FlatCostStatus flatCostStatus;
	
	/** 金额*/
	@Field
	@Column
	private Double price;
	
	/** 收费日期*/
	@Field
	@Column
	private Date flatCostDate;
	
	/** 经办人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "operator")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;

	@Version
	private Integer version;

	public Long getPkCostPrice() {
		return pkCostPrice;
	}

	public void setPkCostPrice(Long pkCostPrice) {
		this.pkCostPrice = pkCostPrice;
	}

	public TravelContract getTravelContract() {
		return travelContract;
	}

	public void setTravelContract(TravelContract travelContract) {
		this.travelContract = travelContract;
	}

	public Date getOperateDate() {
		return operateDate;
	}

	public void setOperateDate(Date operateDate) {
		this.operateDate = operateDate;
	}

	public Double getFlatCost() {
		return flatCost;
	}

	public void setFlatCost(Double flatCost) {
		this.flatCost = flatCost;
	}

	public String getCause() {
		return cause;
	}

	public void setCause(String cause) {
		this.cause = cause;
	}

	@JsonSerialize(using = EnumSerializer.class)
	public enum FlatCostStatus {
		Done("已收费"),Nocharge("未收费");

		private String display;

		FlatCostStatus(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Date getFlatCostDate() {
		return flatCostDate;
	}

	public void setFlatCostDate(Date flatCostDate) {
		this.flatCostDate = flatCostDate;
	}

	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public FlatCostStatus getFlatCostStatus() {
		return flatCostStatus;
	}

	public void setFlatCostStatus(FlatCostStatus flatCostStatus) {
		this.flatCostStatus = flatCostStatus;
	}

}
